Skip to content

std::os::windows::net: add Unix-domain socket support (AF_UNIX on Windows)#147335

Closed
kouhe3 wants to merge 15 commits intorust-lang:masterfrom
kouhe3:win-af-unix
Closed

std::os::windows::net: add Unix-domain socket support (AF_UNIX on Windows)#147335
kouhe3 wants to merge 15 commits intorust-lang:masterfrom
kouhe3:win-af-unix

Conversation

@kouhe3
Copy link
Contributor

@kouhe3 kouhe3 commented Oct 4, 2025

r? rust-lang/libs-api

Summary

This PR adds Unix-domain socket support to the Windows port of the standard library,
mirroring the existing APIs in std::os::unix::net.
The implementation is gated behind the unstable feature windows_unix_domain_sockets;
track issue #56533 .

Motivation / Background

Windows 10 17063+ officially support AF_UNIX.
Having the same UnixStream / UnixListener surface on Windows removes the need for
crates such as mio-uds-windows and lets cross-platform code use a single API.

Acknowledgements

most of the code was transplanted from
https://github.com/Azure/mio-uds-windows
(thank you @damonbarry ).
The main delta is switching from the winapi crate to the std.

What is added

module public items
std::os::windows::net UnixStream, UnixListener, SocketAddr, sockaddr_un

All types mirror their Unix counterparts and implement the usual
Read+Write, AsRawSocket/FromRawSocket/IntoRawSocket, AsSocket, etc.

Feature gate

#![cfg(all(windows, feature = "windows_unix_domain_sockets"))]
#![unstable(feature = "windows_unix_domain_sockets", issue = "56533")]

Testing

Can't run test because rustc ICE

How to try it locally

$ git checkout <your-branch>
$ ./x.py build library --stage 1
$ ./x.py test  library
#![feature(windows_unix_domain_sockets)]
use std::os::windows::net::UnixListener;

Notes for reviewers

  • No unsafe blocks outside sys::pal::windows.
  • All unsafe is restricted to WSASocketW, bind, connect, getsockname, getpeername.
  • sockaddr_un construction follows the Unix implementation: zero-init, copy path, null-term.
  • Drop impl is reused from sys::net::Socket, so closesocket always runs.

Commit message

std::os::windows::net: initial Unix-domain socket support
Adds unstable `windows_unix_domain_sockets` feature that exposes
`UnixStream` and `UnixListener` on Windows 10 17063+.

Code is largely taken from Azure/mio-uds-windows
Co-authored-by: kouhe3
Acked-by: 

Checklist before clicking “Create pull request”

  • ./x.py fmt - clean
  • ./x.py test - passed

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-windows Operating system: Windows T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants